function NavToggle() {
	$(".navbar-minimalize").trigger("click");
}
function SmoothlyMenu() {
	$("body").hasClass("mini-navbar") ? $("body").hasClass("fixed-sidebar") ? ($("#side-menu").hide(), setTimeout(function() {
		$("#side-menu").fadeIn(500);
	}, 300)) : $("#side-menu").removeAttr("style") : ($("#side-menu").hide(), setTimeout(function() {
		$("#side-menu").fadeIn(500);
	}, 100));
}
function localStorageSupport() {
	return "localStorage" in window && null !== window.localStorage;
} 

$(document).ready(function() {
	$(document).click(function(e) { 
	   if ( !($(e.target).hasClass("right-sidebar-toggle") || $(e.target).closest("#right-sidebar").length > 0 ))
	   {
		$(".right-sidebar-toggle").closest("li").removeClass("open") ;
		$("#right-sidebar").removeClass("sidebar-open");
	   }
	});
	
	$(document).on( 'show.bs.dropdown',  function(e) {
          if ( !($(e.target).hasClass("right-sidebar-toggle") || $(e.target).closest("#right-sidebar").length > 0 ))
		   {
			$(".right-sidebar-toggle").closest("li").removeClass("open") ;
			$("#right-sidebar").removeClass("sidebar-open");
		   }
    });
 
	$("#side-menu").metisMenu();

	$(".right-sidebar-toggle").click(function() {
		$("#right-sidebar").toggleClass("sidebar-open");
		$(this).closest("li").toggleClass("open");
		
	});

	$(".sidebar-container").slimScroll({
		height: "100%",
		railOpacity: .4,
		wheelStep: 10
	});
	
	 
	$(function() {
		$(".sidebar-collapse").slimScroll({
			height: "100%",
			railOpacity: .9,
			alwaysVisible: !1
		});
	});
    $(".navbar-minimalize").click(function() {
		$("body").toggleClass("mini-navbar"), SmoothlyMenu();
	});
    
    $(window).bind("load resize click scroll", function() {
		$("body").hasClass("body-small");
	});
     
    $(window).scroll(function() {
		$(window).scrollTop() > 0 && !$("body").hasClass("fixed-nav") ? $("#right-sidebar").addClass("sidebar-top") : $("#right-sidebar").removeClass("sidebar-top");
	});
    $("#side-menu>li").click(function() {
		$("body").hasClass("mini-navbar") && NavToggle();
	});
    $("#side-menu>li li a").click(function() {
		$(window).width() < 769 && NavToggle();
	});
	 $(".nav-close").click(NavToggle);
	 /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) && $("#content-main").css("overflow-y", "auto");
	  
	 if (localStorageSupport) {
		var e = localStorage.getItem("collapse_menu"),
			a = localStorage.getItem("fixednavbar"), 
			l=$("body");
		   "on" == e && $("#collapsemenu").prop("checked", "checked");
		   "on" == e && (l.hasClass("body-small") || l.addClass("mini-navbar"));
		   "on" == a && $("#fixednavbar").prop("checked", "checked");
		   "on" == a && ($(".navbar-static-top").removeClass("navbar-static-top").addClass("navbar-fixed-top"), l.addClass("fixed-nav"));
	}
});

 
$(window).bind("load resize", function() {
	$(this).width() < 769 && ($("body").addClass("mini-navbar"), $(".navbar-static-side").fadeIn());
});

  $(function() {
	  $("#fixednavbar").click(function() {
			$("#fixednavbar").is(":checked") ? ($(".navbar-static-top").removeClass("navbar-static-top").addClass("navbar-fixed-top"), $("body").addClass("fixed-nav"), localStorageSupport && localStorage.setItem("fixednavbar", "on")) : ($(".navbar-fixed-top").removeClass("navbar-fixed-top").addClass("navbar-static-top"), $("body").removeClass("fixed-nav"), localStorageSupport && localStorage.setItem("fixednavbar", "off"));
	 });
	
	$("#collapsemenu").click(function() {
		$("#collapsemenu").is(":checked") ? ($("body").addClass("mini-navbar"), SmoothlyMenu(), localStorageSupport && localStorage.setItem("collapse_menu", "on")) : ($("body").removeClass("mini-navbar"), SmoothlyMenu(), localStorageSupport && localStorage.setItem("collapse_menu", "off"));
	});
	
	$("#boxedlayout").click(function() {
		$("#boxedlayout").is(":checked") ? (launchFullscreen(), localStorageSupport && localStorage.setItem("boxedlayout", "on")) : (launchFullscreen(), localStorageSupport && localStorage.setItem("boxedlayout", "off"));
	});
	
	$(".s-skin-0").click(function() {
		return $("body").removeClass("skin-1"), $("body").removeClass("skin-2"), $("body").removeClass("skin-3"), !1;
	});
	
	$(".s-skin-1").click(function() {
		return $("body").removeClass("skin-2"), $("body").removeClass("skin-3"), $("body").addClass("skin-1"), !1;
	});
	$(".s-skin-3").click(function() {
		return $("body").removeClass("skin-1"), $("body").removeClass("skin-2"), $("body").addClass("skin-3"), !1;
	});
	
	//Logout Confirmation
	$('#logoutConfirm').popup({
		pagecontainer: '.container',
		transition: 'all 0.3s'
	});
	 
});

  function launchFullscreen() { 
		if ($("#boxedlayout").is(":checked") ) {
  
			var docElm = document.documentElement;
	        if (docElm.requestFullscreen) {
	            docElm.requestFullscreen();
	        }
	        else if (docElm.msRequestFullscreen) {
	            docElm.msRequestFullscreen();
	        }
	        else if (docElm.mozRequestFullScreen) {
	            docElm.mozRequestFullScreen();
	        }
	        else if (docElm.webkitRequestFullScreen) {
	            docElm.webkitRequestFullScreen();
	        }

		} else {
			 
			if (document.exitFullscreen) {
	            document.exitFullscreen();
	        }
	        else if (document.msExitFullscreen) {
	            document.msExitFullscreen();
	        }
	        else if (document.mozCancelFullScreen) {
	            document.mozCancelFullScreen();
	        }
	        else if (document.webkitCancelFullScreen) {
	            document.webkitCancelFullScreen();
	        }
		} 
}

  


//显示错误信息，自动隐藏
function showErrorMsg(msg) {
	try {
		$(".errorInfo").text(msg);
		$(".errorInfo").show().delay(3000).fadeOut(200);
	} catch (e) {
		alert(e);
	}
}

// 显示操作成功信息，自动隐藏
function showSuccessMsg(msg) {
	try {
		$(".succeedInfo").text(msg);
		$(".succeedInfo").show().delay(3000).fadeOut(200);
	} catch (e) {
		alert(e);
	}
}

top.showErrorMsg =showErrorMsg;
top.showSuccessMsg =showSuccessMsg;